package com.bll;

import java.io.IOException;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bll.imple.mymienAction.AddMymienAction;
import com.bll.imple.mymienAction.DeleteMymienAction;
import com.bll.imple.mymienAction.ShowMymienAction;
import com.bll.imple.mymienAction.ShowOneMymienAction;
import com.bll.imple.mymienAction.ShowUpdateMymienAction;
import com.bll.imple.mymienAction.ShowfMymienAction;
import com.bll.imple.mymienAction.UpdateMymienAction;
import com.bll.imple.mymienAction.UpdateMymienStateAction;
import com.bll.imple.mymienAction.ZhidingMymienAction;
import com.bll.imple.mymienAction.uploadMymienAction;

public class MymienServlet extends HttpServlet {
	private Map map=new HashMap();
	/**
	 * Constructor of the object.
	 */
	public MymienServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		   request.setCharacterEncoding("gb2312");
		   response.setCharacterEncoding("gb2312");
		
		   //�õ�·��
		  String path=request.getServletPath();
		  //��ȡ·��
		  String acname=path.substring(path.lastIndexOf("/")+1, path.length()-5);
		  System.out.println(acname);
		  //��ݵõ���acname ʵ������
		  Action action =(Action)map.get(acname);
		  //�õ�Ŀ���ַ
		  String despath=action.execute(request, response);
		  System.out.println(despath);
		  //������ת��
		  request.getRequestDispatcher(despath).forward(request, response);
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 doGet( request, response);
	
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		
		//map.put("UpdateMymien", new UpdateMymienAction());
		map.put("DeleteMymien", new DeleteMymienAction() );
		map.put("ShowMymien", new ShowMymienAction() );
		map.put("ShowfMymien", new ShowfMymienAction() );
		map.put("uploadMymien", new uploadMymienAction());
		map.put("ShowOneMymien", new ShowOneMymienAction());
		map.put("ShowUpdateMymien", new ShowUpdateMymienAction());
		map.put("UpdateMymienState", new UpdateMymienStateAction());
		map.put("ZhidingMymien", new ZhidingMymienAction());
	}

}
